import numpy
from numpy.linalg import inv
from matplotlib import pyplot
#线性回归
data=numpy.loadtxt('./ex0.txt',delimiter='\t')
X=data[:,:2]
Y=data[:,2]
param=numpy.empty((30,2))
lam=numpy.exp(numpy.arange(-10,20))
for i in range(30):
    W=(inv((X.T@X+lam[i]*numpy.eye(2)))@X.T)@Y
    param[i,:]=W
pyplot.plot(numpy.log(lam),param[:,0],label='b')
pyplot.plot(numpy.log(lam),param[:,1],label='a')
pyplot.legend()
pyplot.xlabel('$\ln\lambda$')
pyplot.show()